import {IMyObject, MyObject} from "./MyObject";
import {IStudent} from "./Student";
import { ITeacher } from "./Teacher";
import { SubjectType } from "./Subject";

export interface IMyClass extends IMyObject {
  id: number

  addStudent(student: IStudent): void

  addStudents(students: IStudent[]): void

  showGrade(): void

  addTeacher(teacher:ITeacher):void

  showSubject():void
}

export class MyClass extends MyObject implements IMyClass {
  id = 0;

  private students: Map<number, IStudent> = new Map<number, IStudent>();
  private teachers: ITeacher[]=[]
  constructor(id: number) {
    super(`${id}班`);
  }

  addStudent(student: IStudent): void {
    this.students.set(student.id, student);
  }

  addStudents(students: IStudent[]): void {
    students.forEach((student) => {
      this.addStudent(student)
    })
  }

  showGrade(): void {
    console.log(this.toString())
    console.log("学号 | 姓名 | 语文 | 英语 | 数学 | 物理 | 化学 | 生物 ");
    console.log("---------------------------------");
    this.students.forEach((student) => {
      console.log(`${student.id} | ${student.name} | ${(student.getGradeString(SubjectType.Chinese))} | ${student.getGradeString(SubjectType.English)} | ${student.getGradeString(SubjectType.Math)} | ${(student.getGradeString(SubjectType.Physical))} | ${student.getGradeString(SubjectType.Chemistry)} | ${student.getGradeString(SubjectType.Biology)}`);
    })
  }

  addTeacher(teacher:ITeacher):void{
    this.teachers.push(teacher);
  }


  showSubject():void{
    console.log(this.toString())
    console.log("科目：   语文 | 英语 | 数学 | 物理 | 化学 | 生物");
    console.log("--------------------------------------------------");
    this.teachers.forEach((teacher) => {
      console.log(` 老师：  ${(teacher.getSubTeacher(SubjectType.Chinese))} | ${teacher.getSubTeacher(SubjectType.English)} | ${teacher.getSubTeacher(SubjectType.Math)} | ${teacher.getSubTeacher(SubjectType.Physical)} | ${teacher.getSubTeacher(SubjectType.Chemistry)} | ${teacher.getSubTeacher(SubjectType.Biology)}`);
    })
  }
}